<template>
    <div style="display: flex;line-height: 60px">
        <div style="margin-top: 0px;">
            <i :class="icon" style="color: white; font-size: 20px;cursor: pointer;" @click="collapse"></i>
        </div>
        <div style="flex: 1;text-align: center;font-size: 20px;color: #fafafa">
            <span>宝钢气流热负荷分类与预测系统</span>
        </div>
        <div style="margin-right: 3%; font-size: 135%">
          <el-icon class="el-icon-timer"></el-icon>
          <span>{{currentTime}}</span>
        </div>
        <el-dropdown>
            <span style="color: white;">{{operator_name}} <i class="el-icon-arrow-down" style="color: white; margin-left: 5px;"></i></span>
            <el-dropdown-menu slot="dropdown" style="margin-top: -20px">
                <el-dropdown-item @click.native="logout" >退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
    </div>
</template>

<script>
    export default {
        name: "Header",
        data(){
            return {
              currentTime:'',
              operator_name : JSON.parse(sessionStorage.getItem('CurUser'))
            }
        },
        props:{
            icon:String
        },
        methods:{
            updateCurrentTime(){
              const now = new Date();
              const year = now.getFullYear();
              const month = ('0' + (now.getMonth() + 1)).slice(-2); // 加1是因为月份是从0开始的
              const day = ('0' + now.getDate()).slice(-2);
              const hours = ('0' + now.getHours()).slice(-2);
              const minutes = ('0' + now.getMinutes()).slice(-2);
              const seconds = ('0' + now.getSeconds()).slice(-2);

              this.currentTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            },
            logout(){
                console.log('logout')
                this.$confirm('您确定要退出登录吗?', '提示', {
                    confirmButtonText: '确定',  //确认按钮的文字显示
                    type: 'warning',
                    center: true, //文字居中显示
                })
                    .then(() => {
                        this.$message({
                            type:'success',
                            message:'退出登录成功'
                        })
                        this.$router.replace("/")
                        this.SaResultOut()
                        sessionStorage.clear()
                    })
                    .catch(() => {
                        this.$message({
                            type:'info',
                            message:'已取消退出登录'
                        })
                    })

            },
            collapse(){
                this.$emit('doCollapse')
            },
            SaResultOut(){
              this.$axios.get(this.$LoginHttpUrl+'/login/logout')
            }
        },
        // created(){
        //     this.$router.push("/Home")
        // },
        mounted(){
            this.updateCurrentTime()
            setInterval(()=>{
                this.updateCurrentTime()
            },1000)
        }
    }
</script>
<style>

</style>
